package ec.atreasure.com.core.net.rx;

import android.content.Context;

import java.io.File;
import java.util.WeakHashMap;

import ec.atreasure.com.core.net.RestClient;
import ec.atreasure.com.core.net.RestClientBuilder;
import ec.atreasure.com.core.net.callback.IError;
import ec.atreasure.com.core.net.callback.IFailure;
import ec.atreasure.com.core.net.callback.IRequest;
import ec.atreasure.com.core.net.callback.ISuccess;
import ec.atreasure.com.core.ui.LoaderStyle;
import okhttp3.RequestBody;

/**
 * Description :RxRestClient建造者
 * Created by wangjin on 2019/6/25.
 * Job number：
 * Phone ：18301070822
 * Email： 120182051@qq.com
 * Person in charge : 汪渝栋
 * Leader：
 */
public final class RxRestClientBuilder {

    //请求参数
    private WeakHashMap<String, Object> mParams = new WeakHashMap<>();;

    //请求地址
    private String url = null;

    //put raw,post raw请求体
    private RequestBody body = null;

    //过度动画样式
    private LoaderStyle loaderStyle = null;

    //显示上下文具体到fragment或者activity
    private Context context = null;

    //上传文件
    private File uploadFile = null;

    protected RxRestClientBuilder() {
    }

    public final RxRestClientBuilder withUrl(String url) {
        this.url = url;
        return this;
    }

    public final RxRestClientBuilder withParams(WeakHashMap params) {
        this.mParams.putAll(params);
        return this;
    }

    public final RxRestClientBuilder setLoader(Context context, LoaderStyle loaderStyle) {
        this.context = context;
        this.loaderStyle = loaderStyle;
        return this;
    }

    public final RxRestClientBuilder setLoader(Context context) {
        this.context = context;
        this.loaderStyle = LoaderStyle.BallSpinFadeLoaderIndicator;
        return this;
    }

    public final RxRestClientBuilder setUploadFile(File uploadFile) {
        this.uploadFile = uploadFile;
        return this;
    }

    public final RxRestClientBuilder setUploadFile(String uploadFilePath) {
        this.uploadFile = new File(uploadFilePath);
        return this;
    }

    public final RxRestClientBuilder setRequestBody(RequestBody requestBody) {
        this.body = requestBody;
        return this;
    }

    public final RxRestClient build() {
        return new RxRestClient(mParams, url, body, loaderStyle, uploadFile, context);
    }
}
